using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MMM.Core.Domain;
using ServiceStack.ServiceHost;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using MMM.Services.Base;
using MMM.Services.Operations;
using MMM.Services.Type;

namespace MMM.Services
{

    public class FamilyInfoService : BaseService<FamilyInfo>
    {
        public override object OnPost(FamilyInfo request)
        {
            if (request.Birthday.HasValue)
            {
                if (request.Birthday.Value.Equals(DateTime.MinValue))
                {
                    request.Birthday = null;
                }
            }
            return base.OnPost(request);
        }
    }

    public class FamilyInfoGetSerice : BaseGetService<FamilyInfoPageGet, FamilyInfo>
    {
        protected override string CreateFilter(FamilyInfoPageGet request)
        {
            string sql = string.Empty;
            var lst = request.GetFilter();
            if (lst != null && lst.Count > 0)
            {
                foreach (var item in lst)
                {
                    if (string.IsNullOrEmpty(sql))
                    {
                        if (item.Property == "EmpId")
                        {
                            item.Value = Guid.Parse(item.Value).ToString();
                            sql = item.ToSqlEque();
                        }
                        else
                        {
                            sql = item.ToSqlLike();
                        }
                    }
                    else
                    {
                        if (item.Property == "EmpId")
                        {
                            item.Value = Guid.Parse(item.Value).ToString();
                            sql = item.ToSqlEque();
                        }
                        else
                        {
                            sql = string.Format("{0} and {1}", sql, item.ToSqlLike());
                        }
                    }
                }
            }
            return sql;
        }
    }

    public class FamilyInfoDeleteService : BaseDeleteService<FamilyInfo, FamilyInfoDelete>
    {
    }
}
